package ca.usherbrooke.domus.sipnmove.useragent.controller;

import java.util.HashMap;
import java.util.Map;

import ca.usherbrooke.domus.sipnmove.call.Call;
import ca.usherbrooke.domus.sipnmove.call.CallFactory;
import ca.usherbrooke.domus.sipnmove.sip.SipFacadeListener;
import ca.usherbrooke.domus.sipnmove.useragent.UserAgent;
import ca.usherbrooke.domus.sipnmove.useragent.view.UserAgentView;

/**
 * Controller for unknown SIP call handling
 * 
 * Handle unknown SIP calls
 */
public class SipUnknownCallController implements SipFacadeListener, ActionController {

	/**
	 * User agent to control
	 */
	private UserAgent userAgent;

	/**
	 * User agent view to get information from
	 */
	private UserAgentView userAgentView;

	/**
	 * Call factory used to created new call
	 */
	private CallFactory callFactory;

	@Override
	public void processAck(String callId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processBye(String callId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processCancel(String callId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processInvite(String callId) {
		doAction();
	}

	@Override
	public void processOk(String callId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processRinging(String callId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processTrying(String callId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doAction() {
		// TODO: Use SDP information instead
		Map<String, Object> callInformation = new HashMap<String, Object>();
		callInformation.put("address", this.userAgentView.getAddressTextField().getText());
		callInformation.put("initiated", false);
		
		Call call = callFactory.createCall(callInformation);
		userAgent.addCall(call);
	}

	/**
	 * @return the userAgent
	 */
	public UserAgent getUserAgent() {
		return userAgent;
	}

	/**
	 * @param userAgent the userAgent to set
	 */
	public void setUserAgent(UserAgent userAgent) {
		this.userAgent = userAgent;
	}

	/**
	 * @return the userAgentView
	 */
	public UserAgentView getUserAgentView() {
		return userAgentView;
	}

	/**
	 * @param userAgentView the userAgentView to set
	 */
	public void setUserAgentView(UserAgentView userAgentView) {
		this.userAgentView = userAgentView;
	}

	/**
	 * @return the callFactory
	 */
	public CallFactory getCallFactory() {
		return callFactory;
	}

	/**
	 * @param callFactory the callFactory to set
	 */
	public void setCallFactory(CallFactory callFactory) {
		this.callFactory = callFactory;
	}
	
}
